package twentytwo.command.homework;

import java.util.Iterator;
import java.util.Stack;

public class ICommand implements Command{
    private Stack commands = new Stack();
    //执行命令
    @Override
    public void execute() {
        Iterator iterator = commands.iterator();
        while (iterator.hasNext()){
            ((Command)iterator.next()).execute();
        }
    }
    //添加命令
    public void append(Command cmd){
        if(cmd != this){
            commands.push(cmd);
        }
    }
    //撤销一条命令
    public void undo(){
        if(!commands.empty()){
            commands.pop();
        }
    }
    //删除所有命令
    public void clear(){
        commands.clear();
    }
}
